package UILayer;
import CtrLayer.*;

public class StatisticsUI extends InOut
{

    private static StatisticsCtr statisticsCtr= new StatisticsCtr();
    public StatisticsUI()
    {

    }

    public void statisticsMenu()
    {   String[] statisticsMenu = {"Statistics MENU", "Sales statistics", "Customers statistics", "Employees statistics", "Contractors statistics", "Products statistics","EXIT"};
        printMenu(statisticsMenu);
    }

    public void start()
    {
        boolean exit = false;
        while(!exit)
        {
            statisticsMenu();
            int choice = inputInt("Choose: ");
            switch(choice)
            {
                case 1 : {saleStatistics();}break;
                case 2 : {customerStatistics();}break;
                case 3 : {employeesStatistics();}break;
                case 4 : {contractorsStatistics();}break;
                case 5 : {productsStatistics();}break;

                default : {writeEnd();exit=true;}break;
            }
        }
    }

    public void saleStatisticsMenu()
    { String[] saleStatisticsMenu = {"Sale Statistics MENU", " Orders completed during a period of time", "Orders canceled during a period of time", "Orders pending during a period of time","EXIT"};
        printMenu(saleStatisticsMenu);
    }

    public void customerStatisticsMenu()
    {String[] customerStatisticsMenu = {"Customer Statistics MENU", "How many completed orders does a customer have?","Customers with pending orders ","EXIT"};
        printMenu(customerStatisticsMenu);}

    public void employeesStatisticsMenu()
    {String[] employeesStatisticsMenu = {"Employees Statistics MENU", "Employee with most sales ","EXIT"};
        printMenu(employeesStatisticsMenu);}

    public void contractorsStatisticsMenu()
    {String[] contractorsStatisticsMenu = {"Contractor Statistics MENU", "List of products provided by a contractor","Most influent contractor","EXIT"};
        printMenu(contractorsStatisticsMenu);}

    public void productsStatisticsMenu()
    {String[] productsStatisticsMenu = {"Products Statistics MENU", "Most sold product ","Low stock products","EXIT"};
        printMenu(productsStatisticsMenu);}

    public void saleStatistics()
    {boolean exit=false;
        while(!exit)
        {saleStatisticsMenu();
            int choice=inputInt("Choose: ");

            switch(choice)
            {case 1 : { String startDate=inputString("Start date (e.g. 28/11/2013) : ");
                    String endDate=inputString("End date (e.g. 28/11/2013) : ");
                    ordersCompleted(startDate,endDate);}break;
                case 2 : { String startDate=inputString("Start date (e.g. 28/11/2013) : ");
                    String endDate=inputString("End date (e.g. 28/11/2013) : ");
                    ordersPending(startDate,endDate);}break;
                case 3 : {String startDate=inputString("Start date (e.g. 28/11/2013) : ");
                    String endDate=inputString("End date (e.g. 28/11/2013) : ");
                    ordersCanceled(startDate,endDate);}break;
                default : {writeEnd();exit=true;}break;}
        }}

    public void ordersCompleted(String startDate,String endDate)
    {if(statisticsCtr.ordersCompletedTime(startDate,endDate)<0) {print ("The date format is invalid.");}
        else {print("There are " + statisticsCtr.ordersCompletedTime(startDate,endDate) + "orders completed during the following period of time " + startDate + "-" + endDate);}}

    public void ordersPending(String startDate,String endDate)
    {if(statisticsCtr.ordersPendingTime(startDate,endDate)<0) {print ("The date format is invalid.");}
        else {print("There are " + statisticsCtr.ordersPendingTime(startDate,endDate) + "orders pending during the following period of time " + startDate + "-" + endDate);}}

    public void ordersCanceled(String startDate,String endDate)
    {if(statisticsCtr.ordersCanceledTime(startDate,endDate)<0) {print ("The date format is invalid.");}
        else { print("There are " + statisticsCtr.ordersCanceledTime(startDate,endDate) + "orders canceled during the following period of time " + startDate + "-" + endDate);}}

    public void customerStatistics()
    {boolean exit=false;
        while(!exit)
        {customerStatisticsMenu();
            int choice=inputInt("Choose: ");
            
            switch(choice)
            {case 1 : {int idC = inputInt("Write customer's id: ");
                       activeCust(idC);}break;
             case 2 : {pendingOrders();}break;
             default : {writeEnd();exit=true;}break;}
            }}
    
   public void activeCust(int id)
   {print("The customer with ID number : " + id + " has " + statisticsCtr.ordersCustCompleted(id) + " completed .");}
   public void pendingOrders()
   {statisticsCtr.pendingOrders();}
   
   public void employeesStatistics()
    {boolean exit=false;
        while(!exit)
        {employeesStatisticsMenu();
            int choice=inputInt("Choose: ");
            
            switch(choice)
            {case 1 :  { mostSales();}break;
             default : {writeEnd();exit=true;}break;}
            }}
   
   public void mostSales()
   {statisticsCtr.mostSales();}
   
   public void productsStatistics()
   {boolean exit=false;
        while(!exit)
         {productsStatistcsMenu();
              int choice=inputInt("Choose : ");
              
          switch(choice)
          {case 1 : {mostSoldprod();}break;
           case 2 : {lowstockProd();}break;
           default : {writeEnd();exit=true;} break;}
        }}
   
}
   
    

    